﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.SqlClient;

namespace DotNETX.Authentication.Db.Access
{
    internal static class ParameterUtils
    {
        public static string CreateParam(IDbCommand cmd, string paramName, object paramValue)
        {
            string paramExpression = null;
            IDataParameter param = null;
            if (cmd == null || paramName == null)
            {
                return null;
            }
            param = cmd.CreateParameter();
            param.Value = paramValue;
            if (param is System.Data.OleDb.OleDbParameter)
            {
                System.Data.OleDb.OleDbParameter oleparam = param as System.Data.OleDb.OleDbParameter;
                if (paramValue is DateTime)
                {
                    DateTime dt = (DateTime)paramValue;
                    param.Value = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
                }
            }

            param.ParameterName = "@" + paramName;
            paramExpression = "@" + paramName;

            cmd.Parameters.Add(param);
            return paramExpression;
        }
    }
}
